package com.kayak.emailWorks.quartz.travelDays;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.kayak.dbutil.dao.ComnDao;
import com.kayak.dbutil.sql.SqlRow;
import com.kayak.emailWorks.util.EmailTempletMarket;
import com.kayak.emailWorks.util.SendEmailHtml;
import com.kayak.exception.ErrorException;
import com.kayak.kkweb.sys.SysBeans;


//发送出差天数统计
public class SendTravelDaysSum {

	public static void doIt() throws IOException {
		String username = EmailTempletMarket.FETCHEMAILADDRESS;
		String password = EmailTempletMarket.FETCHMAILPASSAGES;
		String toUser = "shenhf@kayak.com.cn";
		String title = "互金&云服务中心出差天数汇总";
		ComnDao comnDao = SysBeans.getComnDao();
		List<SqlRow> sendList = new ArrayList<SqlRow>();
		try {
			sendList = comnDao.query("Eselecttraveldaysum", new HashMap<String, Object>()).getRows();
		} catch (ErrorException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}					
		StringBuffer demo = new StringBuffer();
		demo.append("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">")
		.append("<html>")  
		.append("<head>")  
		.append("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">")
		.append("<title>出差天數統計表</title>")  
	    .append("<style type=\"text/css\">")  
	    .append(".test{font-family:\"Microsoft Yahei\";font-size: 18px;color: red;}")  
	    .append("</style>")  
	    .append("</head>")  
	    .append("<body>") 
	    .append("<table border='10'>\r\n")
	    .append("<tr>")
	    .append("<td>姓名</td>")
	    .append("<td>电子邮箱</td>")
	    .append("<td>所属部门</td>")	    
	    .append("<td>出差城市</td>")
	    .append("<td>出差天数</td>")
	    .append("<td>出差时间段</td>")
	    .append("<td>出差描述</td>")
	    .append("</tr>");
	    for (Map<String, Object> temp : sendList) {
	    	String name = (String) temp.get("name");
	    	String mail_address = (String) temp.get("mail_address");
	    	String department = (String) temp.get("department");
	    	String travel_cities = (String) temp.get("travel_cities");
	    	String travel_days = (String) temp.get("travel_days");
	    	String travel_time = (String) temp.get("travel_time");
	    	String travle_descripetion = (String) temp.get("travle_descripetion");
	    demo.append("<tr>")
	    	.append("<td>"+name+"</td>")
	    	.append("<td>"+mail_address+"</td>")	
	    	.append("<td>"+department+"</td>")	
	    	.append("<td>"+travel_cities+"</td>")
	    	.append("<td>"+travel_days+"</td>")
	    	.append("<td>"+travel_time+"</td>")
	    	.append("<td>"+travle_descripetion+"</td>")
	    	.append("</tr>");
		}
	    demo.append("</table>")		    
	    	.append("</body>")  
	    	.append("</html>");  
	    String content = "以下是上个月的出差天数统计情况：<br/>"+"请您注意查收~<br/>"+demo.toString();	    
	    new SendEmailHtml().sendAEmail(username, password, title, content, toUser);
		}			
}

